package com.easytodo.ui.project;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.ParsedRequestListener;
import com.easytodo.ItemAdapter;
import com.easytodo.ProjectAdapter;
import com.easytodo.R;
import com.easytodo.Server;
import com.easytodo.entity.Item;
import com.easytodo.entity.Project;

import java.util.Collections;
import java.util.List;

public class ProjectFragment extends Fragment {

    ListView projectList;

    private void init(){
        projectList=getActivity().findViewById(R.id.projectList);
        getData();
    }
    public void getData(){
        Fragment that=this;
        Server.getProject(new ParsedRequestListener<List<Project>>() {
            @Override
            public void onResponse(List<Project> response) {
                Log.v("MD","Project!"+response.toString());
                projectList.setAdapter(new ProjectAdapter(getActivity().getBaseContext(),response,that));
            }

            @Override
            public void onError(ANError anError) {

            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();
        init();
    }

    private ProjectViewModel projectViewModel;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        projectViewModel =
                new ViewModelProvider(this).get(ProjectViewModel.class);
        View root = inflater.inflate(R.layout.fragment_project, container, false);

        return root;
    }
}